package com.course.db;

import java.sql.ResultSet;

public class CourseTime extends ExecuteDB {

	//members
	private int Id;
	private String time;
	private String strSql;
	
	public CourseTime()
	{
		this.Id = 0;
		this.time = "";
	}
	
	public String CountSql()
	{
		this.strSql = "select count(*) from course_time";
		return this.strSql;
	} 
	
	//add a CourseTime
	public boolean add()
	{

		this.strSql="insert into course_time ";
		this.strSql=this.strSql + "(time) ";
		this.strSql=this.strSql + "values('" + this.time + "')";
		System.out.println(this.strSql);
		boolean isAdd = super.exeSql(this.strSql);
        return isAdd;
	}
	
	public int lastid()
	{
		int lid = 0;
		this.strSql = "select last_insert_id() as id from course_time limit 1";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
			if (rs.next())
				lid = rs.getInt("id");
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return lid;
	}
	
	//delete a CourseTime by id
    public boolean delete(int CourseTimeID)
    {
       this.strSql = "delete from course_time where Id in (";
       this.strSql = this.strSql + CourseTimeID +")";

       boolean isDelete = super.exeSql(this.strSql);
       return isDelete;
    }
    
  //initialize CourseTime information
 	public boolean init()
	{
		this.strSql="select * from `course_time` where Id=";
		this.strSql=this.strSql + "'" + this.Id + "'";

		try
		{
			ResultSet rs = super.exeQuery(this.strSql);
			if (rs.next())
			{
				this.Id=rs.getInt("Id");
				this.time=rs.getString("time");
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
			return false;
		}
	}
 	
 	//modify CourseTime infomation
    public boolean modify_course_term()
	{
		this.strSql="update course_time set";
		this.strSql=this.strSql + " time=" + "'" + this.time + "'";
		this.strSql=this.strSql + " where Id=" + this.Id;
		
		boolean isUpdate = super.exeSql(this.strSql);

		return isUpdate;
	}
 	
 	//show CourseTime
    public ResultSet show_course_terms()
	{
		this.strSql="select * from `course_time`";
		ResultSet rs = null;
		try
		{
			rs = super.exeQuery(this.strSql);
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return rs;
	}

	public int getId() {
		return Id;
	}

	public void setId(int id) {
		Id = id;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getStrSql() {
		return strSql;
	}

	public void setStrSql(String strSql) {
		this.strSql = strSql;
	}
    
    
}
